package com.kexinde.wjifen.dao;

import java.util.List;

import com.kexinde.wjifen.model.ShopProduct;
import com.kexinde.wjifen.util.JdbcTemplate;

/**
 * 商家礼品数据库操作类
 * 
 * @author vincent
 * 
 */
public class ShopProductDao {

	
	/**
	 * 查询5个热门商家礼品兑换,index页显示
	 * @return
	 * 热门商家礼品集合，以兑换次数排序
	 * @throws Exception
	 */
	public List<ShopProduct> queryIndexShopProducts() throws Exception {
		String sql = "select id,name,point,oldPrice,amount,profile,pic,shopId,insTime from tb_shopproduct" +
				" order by amount desc limit ?,?;";
		Object[] params = { 0, 10 };
		return JdbcTemplate.queryList("com.kexinde.wjifen.model.ShopProduct", sql,
				params, 9);
	}

	/**
	 * 根据店铺id查找该店铺的最新的六件礼品
	 * 
	 * @param shopId
	 * @return 
	 * 		店铺的最新六件礼品
	 * @throws Exception
	 */
	public List<ShopProduct> findByShopId(Long shopId) throws Exception {
		String sql = "select id,name,point,oldPrice,amount,profile,pic,shopId,insTime from tb_shopproduct" +
				" where shopId = ? order by insTime desc limit ?,?;";
		Object[] params = {shopId, 0, 6 };
		return JdbcTemplate.queryList("com.kexinde.wjifen.model.ShopProduct", sql,
				params, 9);
	}

}
